package com.itheima.server;

import com.itheima.util.Constants;
import org.w3c.dom.ls.LSOutput;

import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

public class ServerChat {
    //定义一个集合存放所有的socket
    public static Map<Socket,String> onLineSockets=new HashMap<>();
    public static void main(String[] args) throws UnknownHostException {
        System.out.println(InetAddress.getLocalHost().getHostAddress());
        try{
            //注册端口
            ServerSocket serverSocket=new ServerSocket(Constants.PORT);
            //建立一个死循环等待与所有的socket连接
            while(true){
                Socket socket=serverSocket.accept();
                //每个socket交由一个线程处理
                new ServerReader(socket).start();
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
